unit genericWNDataForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, NumEdit, PBCheckLB, Buttons;

type
  TgenericWNDataScreen = class(TForm)
    Panel1: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    instancMethodEdit: TEdit;
    imStringEdit: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    OpenDialog1: TOpenDialog;
    Label4: TLabel;
    passNameEdit: TEdit;
    Label5: TLabel;
    iterationsEdit: TIntEdit;
    Label1: TLabel;
    workNodesCombo: TComboBox;
    BitBtn1: TBitBtn;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure imStringEditMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure workNodesComboChange(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
    workNodeIndex : Integer;
    dataType : Integer;
    tmpList : TPBCheckListBox;
  public
    { Public declarations }
    procedure myShow(screenCaption, instancingValue, imStrData : String; dType : Integer);
  end;

var
  genericWNDataScreen: TgenericWNDataScreen;

implementation

uses workNode, globals, mainScreen, PassLookUpForm;

{$R *.dfm}

procedure TgenericWNDataScreen.myShow(screenCaption, instancingValue, imStrData : String; dType : Integer);
var
  i : Integer;
begin
dataType := dType;
case dataType of
  WORK_NODE_TYPE:
                 begin
                   tmpList := globalView.wnList;
                   iterationsEdit.Text := '0';
                   passNameEdit.text := '';
                   iterationsEdit.Visible := true;
                   passNameEdit.Visible := true;
                   BitBtn1.Visible := true;
                   label4.Visible := true;
                   label5.Visible := true;
                 end;
  RESOURCE_TYPE:
                 begin
                   tmpList := globalView.resList;
                   iterationsEdit.Visible := false;
                   passNameEdit.Visible := false;
                   BitBtn1.Visible := false;
                   label4.Visible := false;
                   label5.Visible := false;
                 end;
  PASS_TYPE:
                 begin
                 end;
end;

  Caption := screenCaption;
  instancMethodEdit.Text := instancingValue;
  imStringEdit.Text := imStrData;
  Label1.Visible := false;
  workNodesCombo.Visible := false;

  workNodeIndex := tmpList.ItemIndex;

  if instancingValue = 'LoadFromFile' then
    begin
      Button3.Visible := true;
      imStringEdit.Enabled := true;
    end
  else if instancingValue = 'Runtime' then
    begin
      Button3.Visible := false;
      imStringEdit.Enabled := false;
    end
  else // Copy from Another
    begin
      Label1.Visible := true;
      workNodesCombo.Visible := true;
      workNodesCombo.Items.Clear;

      for i:=0 to tmpList.Count-1 do
        begin
          if(i <> tmpList.ItemIndex) then
            workNodesCombo.Items.Add( tmpList.Items.Strings[i] );
        end;

    end;
  showModal;
end;

procedure TgenericWNDataScreen.Button1Click(Sender: TObject);
begin
case dataType of
WORK_NODE_TYPE:
               begin
                 baseClassData(WN_DataList.Items[workNodeIndex]).set_instancingMethod(instancMethodEdit.Text);
                 baseClassData(WN_DataList.Items[workNodeIndex]).set_imStringData(imStringEdit.Text);
                 baseClassData(WN_DataList.Items[workNodeIndex]).set_passName(passNameEdit.Text);
                 baseClassData(WN_DataList.Items[workNodeIndex]).set_iterations(StrToInt(iterationsEdit.Text));
                 globalView.wnListClick(nil);
               end;

RESOURCE_TYPE :
               begin
                 baseClassData(Resources_DataList.Items[workNodeIndex]).set_instancingMethod(instancMethodEdit.Text);
                 baseClassData(Resources_DataList.Items[workNodeIndex]).set_imStringData(imStringEdit.Text);
                 baseClassData(Resources_DataList.Items[workNodeIndex]).set_passName(passNameEdit.Text);
                 baseClassData(Resources_DataList.Items[workNodeIndex]).set_iterations(StrToInt(iterationsEdit.Text));
                 globalView.resListClick(nil);
               end;
PASS_TYPE     : ;
end;
close;
end;

procedure TgenericWNDataScreen.FormShow(Sender: TObject);
begin
workNodeIndex := tmpList.ItemIndex;
end;

procedure TgenericWNDataScreen.Button2Click(Sender: TObject);
begin
close();
end;

procedure TgenericWNDataScreen.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
  imStringEdit.Text := OpenDialog1.FileName;
end;

procedure TgenericWNDataScreen.imStringEditMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
imStringEdit.Hint := imStringEdit.Text;
end;

procedure TgenericWNDataScreen.workNodesComboChange(Sender: TObject);
var
  selectedNodeIndex : Integer; // in the worknodes list
begin
selectedNodeIndex := workNodesCombo.ItemIndex;
if workNodesCombo.ItemIndex >= workNodeIndex then
   selectedNodeIndex := workNodesCombo.ItemIndex + 1;

if dataType = WORK_NODE_TYPE then
  begin
    imStringEdit.Text := workNodesCombo.Items.Strings[workNodesCombo.ItemIndex];
    passNameEdit.Text := baseClassData(WN_DataList.Items[selectedNodeIndex]).get_passName();
    iterationsEdit.Text := intToStr(baseClassData(WN_DataList.Items[selectedNodeIndex]).get_iterations());
  end
else if dataType = RESOURCE_TYPE then
  begin
    imStringEdit.Text := workNodesCombo.Items.Strings[workNodesCombo.ItemIndex];
    passNameEdit.Text := baseClassData(Resources_DataList.Items[selectedNodeIndex]).get_passName();
    iterationsEdit.Text := intToStr(baseClassData(Resources_DataList.Items[selectedNodeIndex]).get_iterations());
  end;
end;

procedure TgenericWNDataScreen.BitBtn1Click(Sender: TObject);
var
 tmp : String;
begin
passLookUpScreen.showModal;
if passLookUpScreen.get_SelectedPassName(tmp) = true then
  passNameEdit.Text := tmp;
end;

end.
